package com.crpc.core.config;

import com.crpc.common.utils.IdGenerator.IdGenerationStrategy;
import com.crpc.common.utils.IdGenerator.IdGeneratorSnowflake;
import com.crpc.core.compress.Compressor;
import com.crpc.core.compress.impl.GzipCompressor;
import com.crpc.core.discovery.RegistryConfig;
import com.crpc.core.loadBalance.LoadBalance;
import com.crpc.core.loadBalance.impl.RoundRobinLoadBalance;
import com.crpc.core.serialize.Serializer;
import com.crpc.core.serialize.impl.HessianSerializer;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author cloud
 * @version 1.0
 * @description: 全局配置类，代码配置>xml配置>spi配置>默认配置
 * @date 2024/2/28 21:14
 */
@Data
@Slf4j
public class Configuration {
    //端口号
    public String port = "528";
    //应用名称
    private String applicationName = "default";
    //注册中心
    private RegistryConfig registryConfig = new RegistryConfig("zookeeper://127.0.0.1:21810");
    //序列化协议
    private Serializer serializer = new HessianSerializer();
    //id生成器
    private IdGenerationStrategy idGenerator = new IdGeneratorSnowflake(1, 1);
    //压缩协议
    private Compressor compressor = new GzipCompressor();
    //序列化协议
    private String serializerType = "hessian";
    //压缩协议
    private String compressorType = "gzip";
    //负载均衡
    private LoadBalance loadBalance = new RoundRobinLoadBalance();
    //服务提供者ip
    private String providerHost = "127.0.0.1";
    //消费者者ip
    private String consumerHost = "127.0.0.1";

    public Configuration() {
        //成员变量的默认项
        //读取xml 获取成员变量信息
        XmlResolver xmlResolver = new XmlResolver();
        xmlResolver.loadConfigurationFromXml(this);
        // 读取spi 机制
        SpiResolver spiResolver = new SpiResolver();
        spiResolver.loadConfigurationFromSpi(this);
        //代码配置CrpcBootStrap 提供
    }

    public static void main(String[] args) {
        Configuration configuration = new Configuration();
    }
}


